package com.dk.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dk.data.Result;
import com.dk.entity.DtBrand;
import com.dk.service.IDtBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("brand")
@Api("品牌的管理")
public class BrandController {

    @Autowired
    private IDtBrandService brandService;

    @GetMapping("selectBrand")
    @ResponseBody
    @ApiOperation("品牌的查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页数", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, paramType = "query"),
    })
    public Result selectBrand(@RequestParam(defaultValue = "1") Integer pageNum ,
                              @RequestParam(defaultValue = "5") Integer pageSize){

        IPage<DtBrand> mapIPage = brandService.selectPage(pageNum , pageSize);
        return Result.ok().setData(mapIPage);
    }

    @PostMapping("addBrand")
    @ResponseBody
    @ApiOperation("品牌的增加")
    public Result addBrand(DtBrand dtBrand){
        brandService.addBrand(dtBrand);
        return Result.ok();
    }

    @PostMapping("updateBrand")
    @ResponseBody
    @ApiOperation("修改品牌")
    public Result updateBrand(DtBrand dtBrand){
        brandService.update(dtBrand);
        return Result.ok();
    }

    @PostMapping("selectById")
    @ResponseBody
    @ApiOperation("根据iid查询")
    public Result selectById(Long id){
        DtBrand dtBrand = brandService.selectById(id);
        return Result.ok().setData(dtBrand);
    }

    @PostMapping("deleteBrandById")
    @ResponseBody
    @ApiOperation("根据id删除数据")
    public Result deleteBrand(Long id){
        brandService.deleteBrandById(id);
        return Result.ok();
    }
}
